@extends('layouts.head')


@section('content')
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #20a0ff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 124px;
    height: 124px;
    line-height: 124px;
    text-align: center;
  }
  .avatar {
    width: 124px;
    height: 124px;
    display: block;
  }
</style>

<section class="content" v-cloak id="content">
<div class="box box-solid" >
  <div class="box-header with-border">
    <el-button-group>
          <el-button @click="addBrandV = true " type="primary"  size="small" >添加</el-button>
          <el-button @click="getNew"   size="small" >刷新</el-button>
          <el-button  @click="editRow()"  :disabled="!isCheckOne"  size="small">编辑</el-button>
          <el-button  @click="delRow()" type="danger" size="small">删除</el-button>
    </el-button-group> 
    <el-button size="small" type=""  @click="yesterday" icon="arrow-left"></el-button>
    <el-date-picker v-model="date" style="width: 120px" size="small" type="date" placeholder="选择日期" > </el-date-picker>
    <el-button  size="small" type="" @click="tomorrow"  icon="arrow-right" ></el-button>


</el-input>
  </div>
  <div class="box-body " >
         <el-table ref="multipleTable" :data="brand" border bordertooltip-effect="dark" border="true"  highlight-current-row
    @current-change="lookRow"   @selection-change="checkOne" style="width: 100%;font-size: xx-small;" >
            <el-table-column type="selection" width="40">  </el-table-column>
            <el-table-column  fixed="left" type="index" width="40" > </el-table-column>
            <el-table-column  fixed="left" label="品牌名称" prop="name"  width="160"> </el-table-column>
            <el-table-column   label="简介" prop="note" width="460"> </el-table-column>
          
        </el-table>
        </br>
        <div class="block">
            <el-pagination @size-change=""  @current-change="getbrandCurrentPage"  :current-page="brandCurrentPage" :page-size="15" layout="total, prev, pager, next, jumper" :total="brandCount">
            </el-pagination>
        </div>
  </div>
</div>



<el-dialog title="添加品牌" :visible.sync="addBrandV"   >
    <table  class="table ">
          <thead>   
          </thead>
          <tr>
           <td style="width: 55px" >品牌</td>
            <td>  
                 <el-input v-model="addBrandItem.name" placeholder="请输入内容"></el-input>
            </td>
            </tr>
            <tr>
            <td style="width: 55px" >简介</td>
            <td>  
                  <el-input type="textarea" :rows="2" placeholder="请输入内容"  v-model="addBrandItem.note">  </el-input>
            </td>
            </tr>
            <!-- <tr>
            <td style="width: 55px" >图片</td>
            <td>
                <el-upload
                  class="avatar-uploader"
                   action="{{asset('img/post/')}}"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload">
                  <img v-if="imgUrl" :src="imgUrl" class="avatar">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>

            </td>
          </tr>
           -->
        </table>
  <span slot="footer" class="dialog-footer">
    <el-button @click="addBrandV = false">取 消</el-button>
    <el-button type="primary" @click="submitAddBrand">确 定 </el-button>
  </span>
</el-dialog>


<el-dialog title="修改品牌" :visible.sync="editBrandV"   >
  
        <table  class="table ">
          <thead>   
          </thead>
          <tr>
           <td style="width: 55px" >品牌</td>
            <td>  
                 <el-input v-model="editBrandItem.name" placeholder="请输入内容"></el-input>
            </td>
            </tr>
            <tr>
            <td style="width: 55px" >简介</td>
            <td>  
                  <el-input type="textarea" :rows="2" placeholder="请输入内容"  v-model="editBrandItem.note">  </el-input>
            </td>
            </tr>
            <!-- <tr>
            <td style="width: 55px" >图片</td>
            <td>
                <el-upload
                  class="avatar-uploader"
                   action="{{asset('img/post/')}}"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload">
                  <img v-if="imgUrl" :src="imgUrl" class="avatar">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>

            </td>
          </tr>
           -->
        </table>
  
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="editBrandV = false">取 消</el-button>
    <el-button type="primary" @click="submitEditBrand">确 定 </el-button>
  </span>
</el-dialog>



</section>
<script >
    var content =new Vue({
        el:'#content',
        data:{
            date:'<?php echo date('Y-m-d') ?>',
            company:'{{ Auth::user()->company }}',
            addBrandV:false,
            editBrandV:false,
            imgV:false,
            imgUrl:'',
            brand:[],
            brandChrildren:[],
            brandCount:1,
            brandCurrentPage:1,
            type:0,
            addBrandItem:{_token:'',company:'{{ Auth::user()->company }}',name:'',img:'',note:''},
            editBrandItem:{_token:'',name:'',note:''},
            multipleSelection: [],

        },
        created:function(){
            this.$http.get('/brand/getCurrent/'+this.brandCurrentPage+'/'+this.company).then((response) => {this.brand=response.data; console.log(response.data)},(response) =>{ }); 
            this.$http.get('/brand/getCount/'+this.company).then((response) => {this.brandCount=response.data; console.log(response.data)},(response) =>{ });       

        },
        computed: {
              isCheckOne:function(){
                if( this.multipleSelection.length == 1 ){
                  return true;
                }else{
                  return false;
                }
              }
        },
        methods:{
                handleAvatarSuccess(res, file) {
                      this.imgUrl='{{asset('')}}'+res
                    },
                    beforeAvatarUpload(file) {
                      const isJPG = file.type === 'image/jpeg';
                      const isLt2M = file.size / 1024 / 1024 < 2;

                      if (!isJPG) {
                        this.$message.error('上传头像图片只能是 JPG 格式!');
                      }
                      if (!isLt2M) {
                        this.$message.error('上传头像图片大小不能超过 2MB!');
                      }
                      return isJPG && isLt2M;
                    },
              getNew:function(){

                  this.$http.get('/brand/getCurrent/'+this.brandCurrentPage+'/'+this.company).then((response) => {this.brand=response.data; console.log(response.data)},(response) =>{ }); 
                  this.$http.get('/brand/getCount/'+this.company).then((response) => {this.brandCount=response.data; console.log(response.data)},(response) =>{ });       
              },
              getAll:function(){

                  this.$http.get('/brand/getCurrent/'+this.brandCurrentPage+'/'+this.company).then((response) => {this.brand=response.data; console.log(response.data)},(response) =>{ }); 
                  this.$http.get('/brand/getCount/'+this.company).then((response) => {this.brandCount=response.data; console.log(response.data)},(response) =>{ });       

                  this.$http.get('/rules/getAll').then((response) => {this.rules=response.data; console.log('rules,success')},(response) =>{ });

              },
              imgRemove:function(){

              },
              handlePictureCardPreview:function(){

              },
              search:function(){
                  console.log(this.searchWord);
                  this.$http.get('/brand/search/'+this.searchWord).then((response) => {this.brand=response.data; this.brandCount = this.brand.length;console.log('word,brand,success')},(response) =>{ console.log(response);}); 
                  
              } ,
              yesterday:function(){
                  console.log('yesterday');
              },
              tomorrow:function(){
                  console.log('tomorrow');
              },
              submitAddBrand:function(){
                  console.log('submitAddBrand');
                  this.addBrandV = false;
                  this.addBrandItem._token = '{{csrf_token()}}';
                  this.$http.post('/brand/add',this.addBrandItem).then((response)=>{this.$notify.success('添加成功');
                              this.$http.get('/brand/getCurrent/'+this.brandCurrentPage+'/'+this.company).then((response) => {this.brand=response.data; console.log(response.data)},(response) =>{ }); 
                              this.$http.get('/brand/getCount/'+this.company).then((response) => {this.brandCount=response.data; console.log(response.data)},(response) =>{ });       

                        },(response) =>{ this.$notify.error('未知错误')});

              },
              submitEditBrand:function(){
                  console.log('submitEditBrand');
                  this.editBrandV = false;
                  this.editBrandItem._token = '{{csrf_token()}}';
                  this.$http.post('/brand/update/'+this.editBrandItem.id,this.editBrandItem).then((response)=>{this.$notify.info(response.data);
                              this.$http.get('/brand/getCurrent/'+this.brandCurrentPage+'/'+this.company).then((response) => {this.brand=response.data; console.log(response.data)},(response) =>{ }); 
                              this.$http.get('/brand/getCount/'+this.company).then((response) => {this.brandCount=response.data; console.log(response.data)},(response) =>{ });        

                        },(response) =>{ });
              },
              cancelAddBrand:function(){
                  console.log('cancelAddBrand');
              },
              lookRow:function(val){
                  console.log(val);
              },
              editRow:function(){
                 this.editBrandV=true;
                 this.editBrandItem=this.multipleSelection[0]
                  console.log(this.editBrandItem);
              },
              delRow:function(val){
                  console.log(val);
                  this.$http.post('/brand/del',{_token:'{{csrf_token()}}',date:this.multipleSelection}).then((response) => {this.$notify.info(response.data);
                                this.$http.get('/brand/getCurrent/'+this.brandCurrentPage+'/'+this.company).then((response) => {this.brand=response.data; console.log(response.data)},(response) =>{ }); 
                                this.$http.get('/brand/getCount/'+this.company).then((response) => {this.brandCount=response.data; console.log(response.data)},(response) =>{ });       

                          },(response) =>{ }); 

              },
              getbrandCurrentPage:function(val){
                  console.log(val);
                  this.brandCurrentPage=val;
                  this.$http.get('/brand/getCurrent/'+this.brandCurrentPage+'/'+this.company).then((response) => {this.brand=response.data; console.log(response.data)},(response) =>{ }); 
                  this.$http.get('/brand/getCount/'+this.company).then((response) => {this.brandCount=response.data; console.log(response.data)},(response) =>{ });       
              },
            
              checkChange:function(rows){
                     if (rows) {
                        rows.forEach(row => {
                          this.$refs.multipleTable.toggleRowSelection(row);
                        });
                      } else {
                        this.$refs.multipleTable.clearSelection();
                      }
              }, 
              checkOne:function (val) {
                console.log('11');
                console.log(val);
                this.multipleSelection = val;
              } ,
         },

  });
</script>




@endsection

@section('pagejs')

@endsection

        




